var jsonList = {};
var page = 1;
var rows = 20;
var zt_id = getUrlParam('ztid');
var ztna = localStorage.getItem("zt_name");
$(function (){
    $(".zt_id").val(zt_id);
    $(".zt_name").val(ztna);
    //jsonList.sid = ztna;
    console.log(ztna,121212);
    //获取文章的来源
    $.ajax({
        url: baseNews + "/api/data/sys/news/source/list?page=1&rows=200",
        dataType: "json",
        data:{},
        success: function (res) {
            console.log(res, 6666);
            if (res.code == 0) {
                var obj = $(".wz_laiyuan");
                $(res.data.list).each(function (index, key) {
                    obj.append("<option value='" + key.id + "'>" + key.name + "</option>");
                })
            }
        }
    })
    //获取文章状态
    //搜索
    $(".wz_state").change(function () {
        jsonList.state = $(this).val();//文章状态
    })
    $(".zt_state").change(function () {
        jsonList.sstate = $(this).val();//专题状态
    })
    $(".wz_laiyuan").change(function () {
        jsonList.source = $(this).val();//专题状态
    })
    $(".search_btn").on("click",function (){
        var wz_name = $(".wz_name").val();//文章名称
        if (wz_name!=""){
            jsonList.title = wz_name
        }
    getList();
    })
})
getList();
function getList() {
    jsonList.sid=zt_id;
    var result = JSON.stringify(jsonList);
    $.ajax({
        url: baseNews + "/api/data/update/special/articles?page=" + page + "&rows=" + rows,
        type: "post",
        headers: { 'Content-Type': 'application/json' },
        dataType: "json",
        data: result,
        success: function (res) {
            console.log(res, 9090);
            if (res.code == 0) {
                var result = res.data;
                var list = result.list;
                console.log(list, 9999)
                var html = "";
                $("#page").paging({
                    pageNo: page,
                    totalPage: result.totalpage,
                    totalSize: result.totals,
                    callback: function (num) {
                        page = num;
                        getList();
                    }
                })
                $(".ar_list").empty();
                $(list).each(function (index, key) {
                    var state = key.state;
                    var state1 = key.sstate;
                    var type=key.type;
                    var newType="";
                    if (type == 1) {
                        newType = "主线";
                    }
                    if (type == 2){
                        newType = "拓展";
                    }
                    if (type == 3) {
                        newType = "思考讨论";
                    }
                    if (type == 4) {
                        newType = "经验教训";
                    }
                    if (type == 5) {
                        newType = "回应";
                    }
                    var newState = "";
                    var newState1 = "";
                    if (state == 0) {
                        newState = "新建";
                    }
                    if (state == 1) {
                        newState = "已修改";
                    }
                    if (state == 2) {
                        newState = "待审核";
                    }
                    if (state == 3) {
                        newState = "待发布";
                    }
                    if (state == 4) {
                        newState = "已发布";
                    }
                    if (state == 10) {
                        newState = "新匹配";
                    }
                    if (state == -10) {
                        newState = "已忽略";
                    }
                    if (state == -1) {
                        newState = "审核失败";
                    }
                    if (state == -2) {
                        newState = "撤销发布";
                    }
                    //
                    if (state1 == 1) {
                        newState1 = "待审核";
                    }
                    if (state1 == 2) {
                        newState1 = "待发布";
                    }
                    if (state1 == 3) {
                        newState1 = "已发布";
                    }
                    if (state1 == 10) {
                        newState = "有更新";
                    }
                    if (state1 == -1) {
                        newState1 = "审核失败";
                    }
                    if (state1 == -2) {
                        newState1 = "撤销发布";
                    }
                    html += `<div class="main-content" style="margin-left: 0;">
					<div class="o">
						<input class="arc_isc"  type="checkbox"  oid="${key.id}"/>
					</div>
					<div class="th">${key.title}</div>
					<div class="t">${newState}</div>
					<div class="o">${key.sid}</div>
					<div class="th">${key.stitle}</div>
					<div class="o">${newState1}</div>
					<div class="o">${newType}</div>
					<div class="o">${key.top?"是":"否"}</div>
					<div class="t"></div>
				</div>`;
                })
                $(".ar_list").append(html);
            }
        }
    })
    //分页
}
$(function (){
     //录入
    $(".wz_luru").on('click',function (){
        var numCount = 0;
        var ids = '';
        $(".arc_isc").each(function (index, key) {
            if ($(this).prop("checked") == true) {
                numCount++;
                ids = ids + $(this).attr("oid") + ',';
            }
        })
        console.log(numCount, 555);
        ids = ids.substring(0, ids.length - 1);
        if (numCount >= 1) {
            //进行下一步
            var json = {}
            var result = JSON.stringify(json);
            zeroModal.confirm("确定要录入该文章吗？", function () {
                //置顶确认请求数据
                $.ajax({
                    url: baseNews + "/api/data/update/special/input/true?sid=" + zt_id+"&ids=" + ids,
                    type: "post",
                    headers: { 'Content-Type': 'application/json' },
                    dataType: "json",
                    data: result,
                    success: function (res) {
                        if (res.code == 0) {
                            location.reload();
                        } else {
                            zeroModal.alert('录入失败');
                        }
                    }
                })
            });
        } else {
            //遮罩层提示
            zeroModal.alert('请选择至少一篇文章');

        }
    })
    //文章忽略
    $(".wz_hv").on('click', function () {
        var numCount = 0;
        var ids = '';
        $(".arc_isc").each(function (index, key) {
            if ($(this).prop("checked") == true) {
                numCount++;
                ids = ids + $(this).attr("oid") + ',';
            }
        })
        console.log(numCount, 555);
        ids = ids.substring(0, ids.length - 1);
        if (numCount >= 1) {
            //进行下一步
            var json = {}
            var result = JSON.stringify(json);
            zeroModal.confirm("确定要录入该文章吗？", function () {
                //置顶确认请求数据
                $.ajax({
                    url: baseNews + "/api/data/update/special/input/false?sid=" + zt_id + "&ids=" + ids,
                    type: "post",
                    headers: { 'Content-Type': 'application/json' },
                    dataType: "json",
                    data: result,
                    success: function (res) {
                        if (res.code == 0) {
                            location.reload();
                        } else {
                            zeroModal.alert('忽略失败');
                        }
                    }
                })
            });
        } else {
            //遮罩层提示
            zeroModal.alert('请选择至少一篇文章');

        }
    })
    //文章置顶
    $(".wz_zhiding").on('click', function () {
        var numCount = 0;
        var ids = '';
        $(".arc_isc").each(function (index, key) {
            if ($(this).prop("checked") == true) {
                numCount++;
                ids = ids + $(this).attr("oid") + ',';
            }
        })
        console.log(numCount, 555);
        ids = ids.substring(0, ids.length - 1);
        if (numCount >= 1) {
            //进行下一步
            var json = {}
            var result = JSON.stringify(json);
            zeroModal.confirm("确定要文章置顶吗？", function () {
                //置顶确认请求数据
                $.ajax({
                    url: baseNews + "/api/data/update/special/article/top/true?ids=" + ids,
                    type: "post",
                    headers: { 'Content-Type': 'application/json' },
                    dataType: "json",
                    data: result,
                    success: function (res) {
                        if (res.code == 0) {
                            location.reload();
                        } else {
                            zeroModal.alert('置顶失败');
                        }
                    }
                })
            });
        } else {
            //遮罩层提示
            zeroModal.alert('请选择至少一篇文章');

        }
    })
    //文章取消置顶
    $(".wz_qxzd").on('click', function () {
        var numCount = 0;
        var ids = '';
        $(".arc_isc").each(function (index, key) {
            if ($(this).prop("checked") == true) {
                numCount++;
                ids = ids + $(this).attr("oid") + ',';
            }
        })
        console.log(numCount, 555);
        ids = ids.substring(0, ids.length - 1);
        if (numCount >= 1) {
            //进行下一步
            var json = {}
            var result = JSON.stringify(json);
            zeroModal.confirm("确定要取消文章置顶吗？", function () {
                //置顶确认请求数据
                $.ajax({
                    url: baseNews + "/api/data/update/special/article/top/false?ids=" + ids,
                    type: "post",
                    headers: { 'Content-Type': 'application/json' },
                    dataType: "json",
                    data: result,
                    success: function (res) {
                        if (res.code == 0) {
                            location.reload();
                        } else {
                            zeroModal.alert('置顶失败');
                        }
                    }
                })
            });
        } else {
            //遮罩层提示
            zeroModal.alert('请选择至少一篇文章');

        }
    })

    //添加免责
    $(".wz_mianze_add").on('click',function (){
        var numCount = 0;
        var ids = '';
        $(".arc_isc").each(function (index, key) {
            if ($(this).prop("checked") == true) {
                numCount++;
                ids = ids + $(this).attr("oid") + ',';
            }
        })
        console.log(numCount, 555);
        ids = ids.substring(0, ids.length - 1);
        if (numCount >= 1) {
            //进行下一步
            var json = {}
            var result = JSON.stringify(json);
            zeroModal.confirm("确定要添加免责声明吗？", function () {
                //置顶确认请求数据
                $.ajax({
                    url: baseNews + "/api/data/update/special/article/statement/true?ids=" + ids,
                    type: "post",
                    headers: { 'Content-Type': 'application/json' },
                    dataType: "json",
                    data: result,
                    success: function (res) {
                        if (res.code == 0) {
                            location.reload();
                        } else {
                            zeroModal.alert('添加失败');
                        }
                    }
                })
            });
        } else {
            //遮罩层提示
            zeroModal.alert('请选择至少一篇文章');

        }
    })
    //删除免责
    $(".wz_mianze_re").on('click', function () {
        var numCount = 0;
        var ids = '';
        $(".arc_isc").each(function (index, key) {
            if ($(this).prop("checked") == true) {
                numCount++;
                ids = ids + $(this).attr("oid") + ',';
            }
        })
        console.log(numCount, 555);
        ids = ids.substring(0, ids.length - 1);
        if (numCount >= 1) {
            //进行下一步
            var json = {}
            var result = JSON.stringify(json);
            zeroModal.confirm("确定要删除免责声明吗？", function () {
                //置顶确认请求数据
                $.ajax({
                    url: baseNews + "/api/data/update/special/article/statement/false?ids=" + ids,
                    type: "post",
                    headers: { 'Content-Type': 'application/json' },
                    dataType: "json",
                    data: result,
                    success: function (res) {
                        if (res.code == 0) {
                            location.reload();
                        } else {
                            zeroModal.alert('删除失败');
                        }
                    }
                })
            });
        } else {
            //遮罩层提示
            zeroModal.alert('请选择至少一篇文章');

        }
    })
    //推荐
    $(".wz_tj").on('click', function () {
        var numCount = 0;
        var ids = '';
        $(".arc_isc").each(function (index, key) {
            if ($(this).prop("checked") == true) {
                numCount++;
                ids = ids + $(this).attr("oid") + ',';
            }
        })
        console.log(numCount, 555);
        ids = ids.substring(0, ids.length - 1);
        if (numCount >= 1) {
            //进行下一步
            var json = {}
            var result = JSON.stringify(json);
            zeroModal.confirm("确定要推荐吗？", function () {
                //确定要推荐
                $.ajax({
                    url: baseNews + "/api/data/update/special/article/recommend/true?ids=" + ids,
                    type: "post",
                    headers: { 'Content-Type': 'application/json' },
                    dataType: "json",
                    data: result,
                    success: function (res) {
                        if (res.code == 0) {
                            location.reload();
                        } else {
                            zeroModal.alert('推荐失败');
                        }
                    }
                })
            });
        } else {
            //遮罩层提示
            zeroModal.alert('请选择至少一篇文章');

        }
    })
    //取消推荐
    $(".wz_qxtj").on('click', function () {
        var numCount = 0;
        var ids = '';
        $(".arc_isc").each(function (index, key) {
            if ($(this).prop("checked") == true) {
                numCount++;
                ids = ids + $(this).attr("oid") + ',';
            }
        })
        console.log(numCount, 555);
        ids = ids.substring(0, ids.length - 1);
        if (numCount >= 1) {
            //进行下一步
            var json = {}
            var result = JSON.stringify(json);
            zeroModal.confirm("确定要推荐吗？", function () {
                //确定要推荐
                $.ajax({
                    url: baseNews + "/api/data/update/special/article/recommend/false?ids=" + ids,
                    type: "post",
                    headers: { 'Content-Type': 'application/json' },
                    dataType: "json",
                    data: result,
                    success: function (res) {
                        if (res.code == 0) {
                            location.reload();
                        } else {
                            zeroModal.alert('推荐失败');
                        }
                    }
                })
            });
        } else {
            //遮罩层提示
            zeroModal.alert('请选择至少一篇文章');

        }
    })
})
$(function (){
    //获取文章来源
    $.ajax({
        url: baseNews + "/api/data/special/channel/select",
        success: function (res) {
            console.log(res);
            if (res.code == 0) {
                var obj = $(".ad_select");
                var obj1 = $(".pd_list");
                $(res.data).each(function (index, key) {
                    obj.append("<option value='" + key.id + "'>" + key.value + "</option>");
                    obj1.append("<option value='" + key.id + "'>" + key.value + "</option>");
                })
            }
        }
    })
})
$(function (){
    // $('#demo-3').fdatepicker({
    //     format: 'yyyy-mm-dd hh:ii',
    //     pickTime: true
    // });
    // var sd_pipei = $(".sd_pipei").val() + ":00";//更新时间
    $(".sd_button").on('click', function () {
        $.ajax({
            url: baseNews + "/api/data/special/match/" + zt_id,
            success: function (res) {
                if (res.code == 0) {
                    location.reload();
                } else {
                    zeroModal.alert('专题手动更新失败');
                }
            }
        })
    })
})
$(function (){
    //获取专题的标签详情
    var json = {}
    var result = JSON.stringify(json);
    $.ajax({
        url: baseNews + "/api/data/special/keywords/" + zt_id,
        type: "post",
        headers: { 'Content-Type': 'application/json' },
        dataType: "json",
        data: result,
        success: function (res) {
            if (res.code == 0) {
                $(".add_biaoq").val(res.data)
            } else {
               
            }
        }
    })
    //保存关键字
    $(".save_key").on('click', function () {
        // var json = {}
        // var result = JSON.stringify(json);
        // var tags='';
        // $(".tag").each(function (index, key) {
        //     var cont = $(this).find("span").html();
        //     for (var i = 0; i < bxlist.length; i++) {
        //         if (bxlist[i].tag == cont) {
        //             tags = tags + bxlist[i].id + ","
        //         }
        //     }

        // })
        // tags = tags.substring(0, tags.length - 1);
        // if(tags==""){
        //     zeroModal.alert("请输入关键字");
        //     return  false;
        // }
        var result = JSON.parse($(".add_biaoq").val());
        var str = JSON.stringify(result);
        var json={
            keywords:str,
            sid: zt_id
        }
        var result1 = JSON.stringify(json);
        console.log(result1)
        $.ajax({
            url: baseNews + "/api/data/special/update/keywords?",
            type: "post",
            headers: { 'Content-Type': 'application/json' },
            dataType: "json",
            data:result1,
            success: function (res) {
                console.log(res,808080)
                if (res.code == 0) {
                    location.reload();
                } else {
                    zeroModal.alert(res.message);
                }
            }
        })
    })
})
$(function (){
    $(".wz_hyall").on('click',function(){

        zeroModal.confirm("确定要忽略录入所有吗？", function () {
            $.ajax({
                url:baseNews+"/api/data/update/special/ignore/"+zt_id,
                success:function (res){
                    if (res.code == 0) {
                        location.reload();
                    } else {
                        zeroModal.alert(res.message);
                    }
                }
            })
        })
    })
})